const {CreateUser,getUserInfo} = require('../service/user.service')
const {userRegisterError}  = require('../constant/err.type')

class UserController{
    async register(ctx,next){
        const {user_name,password} = ctx.request.body

        const res = await CreateUser(user_name,password)

        try{
            ctx.body = {
                code:0,
                message:'用户注册成功',
                result:{
                    id:res.id,
                    user_name:user_name
                }
            }
        }catch(err){
            console.app.emit('error',userRegisterError,ctx);
        }

        await next()
        
    }

    async login(ctx,next){
        const {user_name,password} = ctx.request.body
        ctx.body = `欢迎回来!${user_name}`

        await next()
    }
}

module.exports = new UserController();